<?php
/**
 * Created by PhpStorm.
 * User: Mac
 * Date: 17/7/27
 * Time: 下午5:52
 */
namespace App\Util;

use Qiniu\Auth;
use Qiniu\Storage\UploadManager;

class QiniuUtil
{
    private static $accessKey = 'X4cIaBYQm61h_uPwU-F8W_DtG_e1X2M_yHjA7PC5';
    private static $secretKey = 'rcvw24rNAwuo3d_grzwgzpzdlpD8HvKnwmLhfyvW';
    public  static $photosBucket = 'photos';
    public static $qiniuHost = 'http://otqtrazuz.bkt.clouddn.com';
    /**
     * 得到OSS实例
     * @return null|Auth
     */
    public static function getOssClient()
    {
        try {
            $ossClient=new Auth(self::$accessKey, self::$secretKey);
        } catch (Exception $e){
            printf(__FUNCTION__ . "creating OssClient instance: FAILED\n");
            printf($e->getMessage() . "\n");
            return null;
        }
        return $ossClient;
    }

    public static function getUploadManager()
    {
        try {
            $obj=new UploadManager();
        } catch (Exception $e){
            printf(__FUNCTION__ . "creating UploadManager instance: FAILED\n");
            printf($e->getMessage() . "\n");
            return null;
        }
        return $obj;
    }

    public static function verifyCallback($contentType, $authorization, $url, $callbackBody){
        $ossClient = self::getOssClient();
        return $ossClient->verifyCallback($contentType, $authorization, $url, $callbackBody);

    }


}